<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class GasFee extends Model
{
    protected $table = 'gas_fee';//表名
    protected $fillable = ['gas_number', 'house_number', 'username', 'start_number', 'end_number', 'unit_price', 'cost', 'cost_type',
        'status', 'consumption', 'pay_type', 'community_id', 'pay_status'];//白名单

    public function indexPage($page, $limit, $communityId)
    {
        $start = ($page - 1) * $limit;
        $res = $this->where('status', 1)->where('community_id', $communityId)->offset($start)->limit($limit)->orderBy('id', 'desc')->get();
        return $res;
    }

    public function indexPageLike($page, $limit, $condition, $communityId)
    {
        $start = ($page - 1) * $limit;
        $query = 'SELECT * FROM `gas_fee` WHERE `community_id`=? AND `status` = 1 and CONCAT(`house_number`,`username`) LIKE ?  ORDER BY(id) desc  limit ?,?';
        $param = '%' . $condition . '%';
        $res = DB::select($query, array($communityId, $param, $start, $limit));
        return json_decode(json_encode($res), true);
    }
}
